<template>
  <el-dialog title="选择作业点"
             :visible.sync="dialogForm"
             width="1100px" 
             append-to-body>
    <base-list ref="workPoint"
               :condition="condition"
               :datas.sync="workPoint"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="作业点名称">
              <auto-search-resource-name @selectName="v=>condition['search_LIKE_resourceName']=v"></auto-search-resource-name>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button type="primary"
                       icon="el-icon-search"
                       @click="loadData">查 询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="workPoint"
                border
                stripe
                max-height="500"
                highlight-current-row 
                @current-change="handleCurrentChange">
        <el-table-column type="index"
                         label="序号"
                         width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column>
        <el-table-column prop="resourceName"
                         label="作业点名称"
                         
                         min-width="130"></el-table-column>
        <el-table-column prop="resourceNo"
                         label="作业点编号"
                         
                         min-width="130"></el-table-column>
        <el-table-column prop="orgName"
                         label="所属单位"
                         
                         min-width="200"></el-table-column>
      </el-table>
    </base-list>

    <div slot="footer"
         class="dialog-footer">
      <el-button @click="dialogForm = false">取 消</el-button>
      <el-button type="primary"
                 @click="handleGetter"
                 :loading="$store.getters.loadingBtn">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  deleteOperationPoint,
  getOperationPointList
} from '@/api/operationPoint/operationPoint'
import autoSearchResourceName from '@/components/autocomplete/autoSearchResourceName'

export default {
  name: 'workPoint',
  components: {
    autoSearchResourceName
  },
  data() {
    return {
      form: this.clearForm(),
      condition: {}, // 查询条件
      workPoint: [], // table数组
      pageSearch: getOperationPointList, // 分页查询api接口
      dialogForm: false,
      checked: true,
      currentRow:null,
      resourceNo:'',
      resourceName:'',
      temp:null
    }
  },
  mounted() {
    getOperationPointList().then(res => {
      this.workPoint = res.data.aaData
    })
  },
  methods: {
    clearForm() {
      return {
        orgId: '',
        orgId:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.id,
        orgName:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.name
      }
    },
    loadData() {
      this.$refs.workPoint.loadData()
    },
     // 确定
    handleGetter() {
      this.dialogForm = false
      this.temp.code = this.currentRow.resourceNo
      this.temp.name = this.currentRow.resourceName
    },
    // 新增
    handleToAdd() {
      addStorageSet(this.form).then(res => {
        this.$message({ message: '新增成功!', type: 'success' })
        this.dialogForm = false
        this.$emit('load')
      })
    },
    // 编辑
    handleToEdit() {
      updateStorageSet(this.form.id, this.form).then(res => {
        this.$message({ message: '编辑成功!', type: 'success' })
        this.dialogForm = false
        this.$emit('load')
      })
    },
    handleCllx(v) {
      if (v === 'JOB_CLLX_HC') {
        this.form.teu = 0
      }
      this.form.typeCode = v
    },
    handleCurrentChange(val) {
        this.currentRow = val
    },
    recRowData(row) {
      this.temp = row
    }
  }
}
</script>

<style scoped>
</style>
